import { createSlice, PayloadAction } from "@reduxjs/toolkit";

export interface AuthState {
  userId: string | null;
  email: string | null;
}

const initialState: AuthState = {
  userId: null,
  email: null,
};

const authSlice = createSlice({
  name: "auth",
  initialState,
  reducers: {
    setLogin(state, action: PayloadAction<{ userId: string; email: string }>) {
      state.userId = action.payload.userId;
      state.email = action.payload.email;
    },
    setLogout(state) {
      state.userId = null;
      state.email = null;
    },
  },
});
export const { setLogin, setLogout } = authSlice.actions;
export default authSlice.reducer;
